Skip to content

fix: add feature flag retry circuit breaker#247

Merged
marandaneto merged 16 commits into
mainfrom
pi-flags-network-retry-circuit-breaker-20260626
Jul 2, 2026
Merged

fix: add feature flag retry circuit breaker#247
marandaneto merged 16 commits into
mainfrom
pi-flags-network-retry-circuit-breaker-20260626

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

Stacked on top of #245 to prototype a circuit breaker for /flags retry behavior in a multithreaded/stateless SDK.

The existing retry is bounded per call, but during a broad connectivity issue many concurrent request threads can each sleep and retry independently. This adds a shared circuit breaker so repeated transient /flags transport failures put the SDK into a short cooldown and subsequent calls fail fast instead of all sleeping/retrying.

💚 How did you test it?

  • dotnet test tests/UnitTests/UnitTests.csproj --filter FullyQualifiedName~HttpClientExtensionsTests
  • git diff --check

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented as a draft stacked PR for review. The circuit opens after consecutive transient /flags failures, fails fast during cooldown, and allows a half-open probe after cooldown. HTTP/API status failures remain non-retryable and do not trip the transient-failure circuit.

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

posthog-dotnet Compliance Report

Date: 2026-07-02 10:41:55 UTC
Duration: 2313ms

✅ All Tests Passed!

16/16 tests passed


Feature_Flags Tests

16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 248ms
Request Payload.Flags Request Uses V2 Query Param 123ms
Request Payload.Flags Request Hits Flags Path Not Decide 113ms
Request Payload.Flags Request Omits Authorization Header 109ms
Request Payload.Token In Flags Body Matches Init 110ms
Request Payload.Groups Round Trip 112ms
Request Payload.Groups Default To Empty Object 110ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 110ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 109ms
Request Payload.Disable Geoip Omitted Defaults To False 109ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 109ms
Request Lifecycle.No Flags Request On Init Alone 4ms
Request Lifecycle.No Flags Request On Normal Capture 114ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 212ms
Request Lifecycle.Mock Response Value Is Returned To Caller 113ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 211ms

@marandaneto

Copy link
Copy Markdown
Member Author

@haacked wdyt about this circuit break approach? (we can also make the 30s configurable)

@marandaneto
marandaneto requested a review from haacked June 26, 2026 19:42
@greptile-apps

greptile-apps Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix: add feature flag retry circuit brea..." | Re-trigger Greptile

Comment thread src/PostHog/Library/HttpClientExtensions.cs
Comment thread src/PostHog/Library/HttpClientExtensions.cs
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread tests/UnitTests/Library/HttpClientExtensionsTests.cs Outdated
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread src/PostHog/Library/HttpClientExtensions.cs
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread tests/UnitTests/Library/HttpClientExtensionsTests.cs
@haacked

haacked commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

@marandaneto I meant to submit the review as a comment, not approval! But I trust you to do the right thing. 😄

@marandaneto

Copy link
Copy Markdown
Member Author

@marandaneto I meant to submit the review as a comment, not approval! But I trust you to do the right thing. 😄

thx for the review, yeah it was just a draft with a concept, will check and work on it on monday, then i can port this change across other sdks that have a similar situation

@marandaneto
marandaneto requested a review from haacked June 27, 2026 09:19
@marandaneto

Copy link
Copy Markdown
Member Author

i re-requested review to remove the approval, but no need to re-review until i address the comments and make it ready for review

Base automatically changed from pi-flags-network-retry-20260624 to main June 29, 2026 08:24
…y-circuit-breaker-20260626

# Conflicts:
#	src/PostHog/Api/PostHogApiClient.cs
#	src/PostHog/Library/HttpClientExtensions.cs
#	tests/UnitTests/Library/HttpClientExtensionsTests.cs
@marandaneto
marandaneto marked this pull request as ready for review June 29, 2026 11:02
@marandaneto
marandaneto requested a review from a team as a code owner June 29, 2026 11:02
@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." | Re-trigger Greptile

@marandaneto
marandaneto requested a review from a team June 30, 2026 06:27
@marandaneto

Copy link
Copy Markdown
Member Author

@PostHog/team-client-libraries still pending here

@ioannisj ioannisj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, left a couple of comments

Comment thread .changeset/quiet-flags-retry.md Outdated
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread src/PostHog/Library/HttpClientExtensions.cs
@marandaneto
marandaneto requested a review from ioannisj July 1, 2026 10:21
@marandaneto
marandaneto requested a review from a team July 1, 2026 10:21

@haacked haacked left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work resolving the earlier feedback! A few more non-blocking suggestions inline.

Comment thread src/PostHog/Library/HttpClientExtensions.cs
Comment thread src/PostHog/Library/HttpClientExtensions.cs Outdated
Comment thread src/PostHog/Library/HttpClientExtensions.cs
Comment thread src/PostHog/Library/HttpClientExtensions.cs
Comment thread tests/UnitTests/Library/HttpClientExtensionsTests.cs
Comment thread tests/UnitTests/Library/HttpClientExtensionsTests.cs
@marandaneto
marandaneto merged commit 256d2df into main Jul 2, 2026
20 checks passed
@marandaneto
marandaneto deleted the pi-flags-network-retry-circuit-breaker-20260626 branch July 2, 2026 10:45
@marandaneto

Copy link
Copy Markdown
Member Author

will wait for people to upgrade/test/complain (hopefully not) this approach before i add to the sdk test harness/spec/port to other SDKs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants